<%@ page import="com.ld.businesscard_manage.bean.BusinessCard" %>
<%@ page import="com.ld.businesscard_manage.service.BusinessCardService" %>
<%@ page import="com.ld.businesscard_manage.service.impl.BusinessCardServiceImpl" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 刘邓
  Date: 2023-06-10
  Time: 16:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查看有效名片</title>
  <style>
    td {
      color: #ff4b2b;
      margin-left: 20px;
      text-align: center;
    }
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    a {
      text-decoration: none;
      color: black;
    }
    .container {
      background-color: #fff;
      border-radius: 10px;
      box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35), 0 10px 10px rgba(0, 0, 0, 0.22);
      position: relative;
      overflow: hidden;
      width: 80%;
      max-width: 100%;
      min-height: 480px;
      margin:0 auto;
    }
  </style>
</head>
<body>
<%!
  private BusinessCardService businessCardService = new BusinessCardServiceImpl();
%>
<%
  List<BusinessCard> cards = businessCardService.getAllValidCards();
  out.println("<a href='/home/manage.jsp' style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:blue'>返回管理页面</a><br>");
  out.println("<a href='/home/addCard.jsp' style='display: inline-block;width:30%,height: 30px;margin:10px 30px;text-align:center;line-height:30px;background-color:orange'>添加名片</a>");
  if (cards.isEmpty()) out.println("<h1 style='width: 80%;height:400px;margin: 0 auto;text-align:center;line-height:400px'>暂无更多信息!<h1>");
  else {
    out.println("<table class='container'>" +
            "<tr>" +
            "<th>id</th>" +
            "<th>姓名</th>" +
            "<th>性别</th>" +
            "<th>账号</th>" +
            "<th>密码</th>" +
            "<th>邮箱</th>" +
            "<th>修改</th>" +
            "<th>放入回收站</th>" +
            "<th>永久删除</th>" +
            "</tr>");
    if (!cards.isEmpty())
      for (BusinessCard card : cards) {
        int sex0 = card.getSex();
        String sex;
        if (sex0 == 0) {
          sex = "男";
        } else {
          sex = "女";
        }
        String changeDOM = "<td><a href=" + "'/home/changeCard.jsp?id=" + card.getId() + "'>修改" + "</a></td>";
        String deleteDOM = "<td><a class='recyle' href=" + "'/home/deleteCard.jsp?id=" + card.getId() + "'>回收站" + "</a></td>";
        String deletedDOM = "<td><a class='deleted' href=" + "'/home/deletedCard.jsp?id=" + card.getId() + "'>永久删除" + "</a></td>";
        out.println("<tr>");
        out.println("<td style='text-align:center'>" + card.getId() + "</td>");
        out.println("<td style='text-align:center'>" + card.getName() + "</td>");
        out.println("<td style='text-align:center'>" + sex + "</td>");
        out.println("<td style='text-align:center'>" + card.getAccount() + "</td>");
        out.println("<td style='text-align:center'>" + card.getPassword() + "</td>");
        out.println("<td style='text-align:center'>" + card.getEmail() + "</td>");
        out.println(changeDOM);
        out.println(deleteDOM);
        out.println(deletedDOM);
        out.println("</tr>");
      }
    out.println("</table>");
  }
%>
</body>
<script>
  let deleted = document.getElementsByClassName("deleted");
  for (let i = 0; i < deleted.length; i++) {
    deleted[i].addEventListener("click",(e) => {
      let b = confirm("你确定要彻底删除吗?");
      if(b == false){
        e.preventDefault();
      }
    })
  }
  let recyle = document.getElementsByClassName("recyle");
  for (let i = 0; i < recyle.length; i++) {
    recyle[i].addEventListener("click",(e) => {
      let b = confirm("你确定要放入回收站吗?");
      if(b == false){
        e.preventDefault();
      }
    })
  }
</script>
</html>
